#!/usr/bin/env python 
# -*- coding:utf-8 -*-
import time

import requests

url_id ='http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList'
url_company = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById'
yjj_file = open('./datas/药监局.text',mode='a',encoding='utf-8')
start_time = time.time()
for i in range(1,355):
    data = {
        'on': 'true',
        'page': i,
        'pageSize': '15',
        'productName': '',
        'conditionType': '1',
        'applyname': '',
        'applysn': '' ,
    }
    try:
        text_json = requests.post(url_id,data=data,timeout=1).json()
        for list in text_json['list']:
            com_data = {
                'id':list['ID']
            }
            com_json = requests.post(url_company,data=com_data,timeout=1).json()
            str_base = "企业名称:{} 许可证编号：{} 许可项目：{} 企业住所：{} 生产地址：{} 社会信用代码：{} 法定代表人：{} 企业负责人：{} 质量负责人：{}\n"
            com_str = str_base.format(com_json['epsName'],com_json['productSn'],com_json['certStr'],com_json['epsAddress'],com_json['epsProductAddress'],
                                      com_json['businessLicenseNumber'],com_json['legalPerson'],com_json['businessPerson'],com_json['qualityPerson'])
            # print(com_str)
            yjj_file.writelines(com_str)
    except Exception as e:
        print(e)
yjj_file.close()
end_time = time.time()
print("时长：",end_time-start_time)